<template>
  <div>
    <el-form
      :model="dataForm"
      :rules="dataRule"
      ref="dataForm"
      @keyup.enter.native="dataFormSubmit()"
      label-width="100px"
    >
      <el-form-item label="机构名称" prop="businessId">
        <el-input disabled
          v-model="dataForm.coname"
          placeholder="机构名称"
        ></el-input>
      </el-form-item>


        <el-input
          v-model="dataForm.businessId" hidden disabled
        ></el-input>

      <el-form-item label="任务名称" prop="beanName">
        <el-input disabled v-model="dataForm.beanName" placeholder="任务名称"></el-input>
      </el-form-item>
      <el-form-item label="参数" prop="params">
        <el-input disabled v-model="dataForm.params" placeholder="参数"></el-input>
      </el-form-item>
      <el-form-item label="cron表达式" prop="cronExpression">
        <el-input
          v-model="dataForm.cronExpression"
          placeholder="cron表达式"
        ></el-input>
      </el-form-item>
      <el-form-item label="任务状态" prop="status">
        <el-switch
          v-model="dataForm.status"
          active-color="#13ce66"
          inactive-color="#ff4949"
          active-value="1"
          inactive-value="0"
          active-text="正常"
          inactive-text="暂停"
          style="float: left; padding-top: 20px"
        >
        </el-switch>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="resetForm('dataForm')">重置</el-button>
      <el-button :disabled="dataForm.createDate!=null" type="primary" @click="dataFormSubmit()">添加</el-button>
      <el-button :disabled="dataForm.createDate==null" type="info" @click="deleteinfo()">停止</el-button>
      <el-button :disabled="dataForm.createDate==null" type="success" @click="dataFormSubmit()">恢复</el-button>
      <el-button :disabled="dataForm.createDate==null" type="warning" @click="update()">修改</el-button>
      <el-button :disabled="dataForm.createDate==null" type="danger" @click="likemake()">立即执行</el-button>


    </span>
  </div>
</template>

<script>
import {deletetripsbyid} from "../../../api/base";
import {addscheduling, deletescheduling, updatescheduling} from "../../../api/dispatch";

export default {
  name: "PindatmsSchedulingAddOrUpdate",

  data() {
    return {
      visible: false,



      //接收查询出的数据
      // data1:this.$router.query.data1,

      dataForm: {
        id: 0,
        beanName: "dispatchTask",
        params: "transfer",
        cronExpression: "",
        status: "",
        remark: "",
        businessId: "",
        coname:"",
        creator: "",
        createDate: "",
        updater: "",
        updateDate: "",
      },
      dataRule: {
        beanName: [
          {
            required: true,
            message: "任务名称不能为空",
            trigger: "blur",
          },
        ],
        params: [{ required: true, message: "参数不能为空", trigger: "blur" }],
        cronExpression: [
          { required: true, message: "cron表达式不能为空", trigger: "blur" },
        ],
        remark: [{ required: true, message: "备注不能为空", trigger: "blur" }],
        businessId: [
          {
            required: true,
            message: "机构名称不能为空",
            trigger: "blur",
          },
        ],
      },
    };
  },
mounted() {
  this.bus.$on('handleNodeClick',params=>{

    console.log(params)
    this.dataForm.coname = params.coname
    this.dataForm.businessId = params.coid
    this.dataForm.cronExpression = params.data.cronExpression
    this.dataForm.status = params.data.status
    this.dataForm.remark = params.data.remark
    this.dataForm.createDate = params.data.createDate

  })

},

  methods: {
    // 修改
    update() {
      let params = {
        'id':this.dataForm.id,
        'beanName': this.dataForm.beanName,
        'params': this.dataForm.params,
        'cronExpression': this.dataForm.cronExpression,
        'status': this.dataForm.status,
        'remark': this.dataForm.remark,
        'businessId': this.dataForm.businessId,
        'creator': this.dataForm.creator,
        'createDate': this.dataForm.createDate,
        'updater': this.dataForm.updater,
        'updateDate': this.dataForm.updateDate,
      }
      updatescheduling(params).then(({ data }) => {
        if (data && data.code === 0) {
          this.$message({
            message: "操作成功",
            type: "success",
            duration: 1500,
          });
        } else {
          this.$message.error(data.msg);
        }
      })
    },
    // 表单提交
    dataFormSubmit() {
          let params = {
            'id':this.dataForm.id,
            'beanName': this.dataForm.beanName,
            'params': this.dataForm.params,
            'cronExpression': this.dataForm.cronExpression,
            'status': this.dataForm.status,
            'remark': this.dataForm.remark,
            'businessId': this.dataForm.businessId,
            'creator': this.dataForm.creator,
            'createDate': this.dataForm.createDate,
            'updater': this.dataForm.updater,
            'updateDate': this.dataForm.updateDate,
          }
          addscheduling(params).then(({ data }) => {
            if (data && data.code === 0) {
              this.$message({
                message: "操作成功",
                type: "success",
                duration: 1500,
              });
            } else {
              this.$message.error(data.msg);
            }
          })

    },



    resetForm(formName) {
      this.$refs[formName].resetFields();
    },

    //停止定时任务
    deleteinfo(){
      var businessId = this.dataForm.businessId;
      deletescheduling(businessId).then(({data}) => {
        if (data && data.code == 0) {
          this.$message({
            message: '删除成功',
            type: 'error',
            duration: 1500,
            onClose: () => {
              this.getDatalineList()
            }
          })
        }
      })
    },

    //立即执行
    likemake(){
      var businessId = this.dataForm.businessId;
      likemakescheduling(businessId).then(({data}) => {
        if (data && data.code == 0) {
          this.$message({
            message: '执行成功',
            type: 'error',
            duration: 1500,
            onClose: () => {
              this.getDatalineList()
            }
          })
        }
      })
    },

  },

};
</script>

<style lang="scss" scoped>
</style>
